#-*- coding:utf-8 -*-
'''
Created on Nov 29, 2012

@author: bbg
'''
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool

class SrvConfig(object):
    '''
        server configurations
    '''
    __dbsession_debug__ = False
    
    __default_mysql_engine__ = None
    __default_session_factory__ = None
    
    __order_mysql_engine__ = None    
    __order_session_factory__ = None
    
    __user_head_picture_root_path__ = "/tmp"
    
    __log_path__ = "/tmp"
    
    __sqlite_file_path__ = "/var/www/wsgi/dbbase"

    def __init__(self):
        pass
    
    @staticmethod
    def getDefaultDBSession():
        if SrvConfig.__default_mysql_engine__ == None:
            SrvConfig.__default_mysql_engine__ = create_engine('mysql://apkpos:apkpos@58.215.189.116:3306/company_management', 
                                                      poolclass = NullPool, 
                                                      connect_args={
                                                                    'charset':'utf8'
                                                      },
                                                      echo = SrvConfig.__dbsession_debug__)
            SrvConfig.__default_session_factory__ = sessionmaker()
            SrvConfig.__default_session_factory__.configure(bind = SrvConfig.__default_mysql_engine__)
        
        session = SrvConfig.__default_session_factory__()
        return session
    
    @staticmethod
    def getOrderDBSession():
        if SrvConfig.__order_mysql_engine__ == None:
            SrvConfig.__order_mysql_engine__ = create_engine('mysql://apkpos:apkpos@58.215.189.116:3306/company_management', 
                                                      poolclass = NullPool, 
                                                      connect_args={
                                                                    'charset':'utf8'
                                                      },
                                                      echo = SrvConfig.__dbsession_debug__)
            SrvConfig.__order_session_factory__ = sessionmaker()
            SrvConfig.__order_session_factory__.configure(bind = SrvConfig.__order_mysql_engine__)
        
        session = SrvConfig.__order_session_factory__()
        return session

    
    @staticmethod
    def getLogPath():
        return SrvConfig.__log_path__
    
    
    @staticmethod
    def getSQLiteFilePath():
        return SrvConfig.__sqlite_file_path__
    
        
        